<template>
  <el-dialog v-model="props.showModal" :title="title" width="800" :before-close="handleClose">
    <!--- ======================================form begin====================================== -->
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="应用图标">
        <fc-upload-img v-model:image-url="form.clientIcon" :file-size="3">
          <template #tip> 上传图片最大为 3M </template>
        </fc-upload-img>
      </el-form-item>
      <el-form-item label="应用名称">
        <el-input v-model="form.clientName" />
      </el-form-item>
      <el-form-item label="客户端认证方式">
        <el-select v-model="form.clientAuthenticationMethods" >
          <el-option label="CLIENT_SECRET_POST" value="client_secret_post" />
          <el-option label="CLIENT_SECRET_BASIC" value="client_secret_basic" />
        </el-select>
      </el-form-item>
      <el-form-item label="回调地址">
        <el-input v-model="form.redirectUris" />
      </el-form-item>
      <el-form-item label="是否自动授权">
        <el-switch v-model="form.requireAutoApprove" />
      </el-form-item>
      <el-form-item label="Scopes">
        <el-checkbox-group v-model="form.scopes">
          <el-checkbox value="message.read" name="scopes">
            message.read 读信息
          </el-checkbox>
          <el-checkbox value="USER" name="scopes">
            USER 用户基本信息
          </el-checkbox>
          <el-checkbox value="message.write" name="scopes">
            message.write 写信息
          </el-checkbox>
          <el-checkbox value="other.scope" name="scopes">
            other.scope 其他
          </el-checkbox>
          <el-checkbox value="profile" name="scopes">
            profile 个人配置
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="GrantTypes">
        <el-checkbox-group v-model="form.authorizationGrantTypes">
          <el-checkbox value="refresh_token" name="authorizationGrantTypes">
            refresh_token
          </el-checkbox>
          <el-checkbox value="client_credentials" name="authorizationGrantTypes">
            client_credentials
          </el-checkbox>
          <el-checkbox value="password" name="authorizationGrantTypes">
            password
          </el-checkbox>
          <el-checkbox value="authorization_code" name="authorizationGrantTypes">
            authorization_code

          </el-checkbox>
          <el-checkbox value="sms_code" name="authorizationGrantTypes">
            sms_code
          </el-checkbox>
          <el-checkbox value="email" name="authorizationGrantTypes">
            email
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>



    <!--- ======================================form end====================================== -->
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="handleClose">Cancel</el-button>
        <el-button type="primary" @click="handleOK">
          Confirm
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue';

// do not use same name with ref
const form = reactive({
  clientIcon: '',
  clientName: '',
  clientAuthenticationMethods: '',
  authorizationGrantTypes: [],
  scopes: [],
  requireAutoApprove: false,
  redirectUris: ''
})

const onSubmit = () => {
  console.log('submit!')
}


const title = ref<string>('标题')

const props = defineProps({
  showModal: { type: Boolean, default: false }
});

const emits = defineEmits(['close']);

const handleClose = (done: () => void) => {
  emits('close')
}

const handleOK = () => {
  emits('close')
}

defineExpose({ title });

</script>

<style lang="scss" scoped></style>